package org.eden.rpc.service.dao;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionFactoryHolder {

    private static final Logger logger = LoggerFactory.getLogger(SqlSessionFactoryHolder.class);

    static SqlSessionFactory sqlSessionFactory;

    static {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
    }

    public static SqlSessionFactory get() {
        return sqlSessionFactory;
    }

}
